package hnlg.com.cn.systemmanage.quyumanage.control;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import hnlg.com.cn.common.RespBean;
import hnlg.com.cn.model.QuyuVo;
import hnlg.com.cn.systemmanage.quyumanage.service.IQuyuService;

@RestController
@RequestMapping("/quyuControl")
public class QuyuManageControl {
RespBean rb=null;
List<QuyuVo> list=null;
@Resource IQuyuService QuyuService;
//http://localhost:8044/test/quyuControl/addquyu?name=松林区
@RequestMapping("/addquyu")
public RespBean addquyu(QuyuVo vo){
	try {
		QuyuService.addQuyu(vo);
		rb=new RespBean("msg","添加成功");
	} catch (Exception e) {
		e.printStackTrace();
		rb=new RespBean("msg","添加失败");
	}
	return rb;
}
//http://localhost:8044/test/quyuControl/deletequyu?id=6
@RequestMapping("/deletequyu")
public RespBean deletequyu(@RequestParam("id") String id){
	try{
		System.out.println("id=="+id);
		QuyuService.deleteQuyu(id);
		rb=new RespBean("msg","删除成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","删除失败");
	}
	return rb;
}
//http://localhost:8044/test/quyuControl/updatequyu?id=5&name=君山区
@RequestMapping("/updatequyu")
public RespBean updatequyu(QuyuVo vo){
	try{
		boolean flag=QuyuService.updateQuyu(vo);
		System.out.println("=="+flag);
		rb=new RespBean("msg","更新成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","更新失败");
	}
	return rb;
}

//http://localhost:8044/test/quyuControl/queryquyu?
@RequestMapping("/queryquyu")
public List<QuyuVo> queryquyu(
@RequestParam(required=false,defaultValue="") String name){
	try{
		QuyuVo vo=new QuyuVo();
		vo.setName(name);
		list=QuyuService.queryquyu(vo);
	}catch(Exception e){
		e.printStackTrace();
	}
	return list;
}

//http://localhost:8044/test/quyuControl/deletebatch?ck=1,2,3,4
@RequestMapping("/deletebatch")
public RespBean deletebatch(@RequestParam("ck") String mycheckbox[]){
	try{
		for(String obj:mycheckbox){
			System.out.println("mycheckbox=="+obj);
		}
		this.QuyuService.deletebatch(mycheckbox);
		rb=new RespBean("success","批量删除成功");
	}catch(Exception e){e.printStackTrace();}
	 rb=new RespBean("success","批量删除失败");
	return rb;
}
}
